package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * load方法
 */
public class JqueryloadServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println(request.getMethod());
		String username=request.getParameter("username");
		System.out.println(username);

		response.getWriter().println("success");
	}

	/**
	 * post方法 
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//建议加上这一步操作，作用是对客户端请求重新编码
		request.setCharacterEncoding("utf-8");
		
		System.out.println(request.getMethod());
		String username=request.getParameter("username");
		System.out.println(username);
		
		//控制台没有编码的错误，而浏览器有编码的错误，所以要多加一个设置编码
		response.setContentType("text/html;charset=utf-8");
		
		//这个json的格式为{"result":"success","msg":"响应成功"}，注意他们之间的符号
		String s="{\"result\":\"success\",\"msg\":\"响应成功\"}";    //"\"这个的作用是对特殊字符进行响应

		response.getWriter().println(s);      //这就是参数
		
		//结果是{result:success;msg:响应成功}因为是text/html这种格式，改成application/json这个模式是json类型
	}

}
